package com.bs.blogspace.controller;


import com.bs.blogspace.anno.Log;
import com.bs.blogspace.model.Result;
import com.bs.blogspace.pojo.AddSpace;
import com.bs.blogspace.pojo.Space;
import com.bs.blogspace.service.SpaceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Slf4j
public class SpaceController {
    @Autowired
    private SpaceService spaceService;
    @Log
    /*创建空间*/
    @PostMapping("/createspace")
    @ResponseBody
    public Result<Space> createSpace(@RequestBody Space space){
      log.info("创建空间，{}",space);
      return spaceService.createSpace(space);

    }

    /*所有空间*/
    @GetMapping("/getAllSpace")
    @ResponseBody
    public Result getAllSpace(){
        log.info("获取所有空间,{}",spaceService.getAllSpace());
        return spaceService.getAllSpace();
    }

    /*单个空间*/
    @GetMapping("/getOneSpace")
    @ResponseBody
    public Result getOneSpace(@RequestParam("spaceId") Integer spaceId){
        log.info("传入参数,{}",spaceId);
        return spaceService.getBySpace(spaceId);
    }


    /*查看指定用户创建的空间*/
    @GetMapping("/getUserCreateSpace")
    @ResponseBody
    public Result queryUserSpace(@Param("phone") String phone){
        log.info("查看指定用户创建的空间,{}",phone);
        return spaceService.queryUserSpace(phone);
    }

}
